package com.szms.mobile.common;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPool {
    private ThreadPool(){

    }

    private static ThreadPool _instance;
    private static Object lockObj = new Object();

    public static ThreadPool getInstance(){
        if (_instance==null){
            synchronized (lockObj){
                if (_instance==null){
                    _instance = new ThreadPool();
                }
            }
        }
        return _instance;
    }

    /**
     * 线程池
     */
    private ExecutorService executor = new ThreadPoolExecutor(100,120,50000, TimeUnit.SECONDS,new ArrayBlockingQueue<>(500));

    public void execute(Runnable runnable){
        executor.execute(runnable);
    }

    public <T> Future<T> submit(Callable<T> callable){
        Future<T> submit = executor.submit(callable);
        return submit;
    }
}
